package com.etc.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.ProcessBuilder.Redirect;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.etc.entity.Admin;
import com.etc.entity.User;
import com.etc.service.AdminService;



/**
 * 自定义一个获取参数的控制器类
 * 
 * @author Administrator
 *
 */
@Controller // 声明这是一个控制器
public class AdminController {
	
	@Resource
	private AdminService as;
	
	@RequestMapping(value = "login",method = RequestMethod.POST) // 请求的地址
	@ResponseBody
	public Map<String,Object> adminLogin(@RequestBody Admin admin, HttpServletRequest request, HttpServletResponse response,Model model) throws IOException {
		
		Map<String,Object>  map = as.login(admin.getAdminName(), admin.getAdminPwd(),request);
	
		if(map.size()>0) {
			
		  request.getSession().setAttribute("Admin", admin);
		  
		}
		return map;
		/*if(admin == null) {
			//out.println("<script>alert('账号或密码错误，登录失败！');location.href='index_admin.jsp'</script>");
			System.out.println("失败登录");
			
			return "login_admin";
			
		}		
			model.addAttribute("admin", admin);
			System.out.println("成功登录");
			return "index_admin";*/
	
		
	}
	
	
	

}
